﻿$(function () {
    var pickerOpts = {
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy/mm/dd",
        dayNamesMin: ["日","一", "二", "三", "四", "五", "六"],
        firstDay: 0,
        nextText: "下一月",
        prevText: "上一月",
        monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        isRTL: false,
        showButtonPanel: false,
        yearRange: "-25:+25"
    }
    $('#startTime').datepicker(pickerOpts);
    $('#endTime').datepicker(pickerOpts);
$("#List tr").dblclick("click", function () {
    var ID = $.trim($(this).children().first().html());
    var rnd = (new Date()).getMilliseconds() + "" + parseInt(Math.random() * 10000);
    window.open("/ITService/views?servicerequestid=" + ID + "&nocache=" + rnd, "_self");
});
$.ajax({
    url: "../WorkList/getAllServiceList",
    type: "GET",
    dataType: "json",
    success: function (data) {
        $.each(data, function (i, item) {
            $("#serviceType").append("<option value=" + item.serviceTypeID + ">" + item.serviceName + "</option>");
        });
    }
});

$("#search_submit").bind("click", function () {
    $("input#index").val(1);
    getToDoWorkList(1);
});

});

function getToDoWorkList() {
    var dater = (new Date()).toString() + Math.random() * 999;
        $.ajax({
            url: "getToDoList_By_params?r=" + dater,
            type: "GET",
            data: { "requestID": $("input#serviceRequestID").val(),
                "userName": $("input#userName").val(),
                "description": $("input#description").val(),
                "startTime": $("input#startTime").val(),
                "endTime": $("input#endTime").val(),
                "serviceTypeID": $("select#serviceType option:selected").val(),
                "ps": parseInt($("input#size").val(), 10),
                "pi": parseInt($("input#index").val(), 10)
                },
            dataType: "json",
            success: function (data) {
                $("#List").empty();

                $("#List").append("<tr><th>申请单号</th><th>服务类别</th><th>申请单描述</th><th>提交人</th><th>提交时间</th></tr>");
                $.each(data.Data.list, function (i, item) {
                    var sername = item.serviceType.serviceName.toString();
                    if (sername.length > 10) {
                        sername = sername.substring(0, 8) + "..";
                    }
                    var desc = "";
                    if (item.description.toString().length > 0) {
                        if (item.description.toString().length > 20) {
                            desc += item.description.toString().substring(0, 17);
                            desc += "...";
                        }
                        else {
                            desc = item.description.toString();
                        }
                    }
                    else {
                        if (item.BDDescription.toString().length > 20) {
                            desc += item.BDDescription.toString().substring(0, 17);
                            desc += "...";
                        }
                        else {
                            desc = item.BDDescription.toString();
                        }
                    }

                    $("<tr id=\"" + item.serviceRequestID + "\" class=\"AlternatingRowStyle\"><td>" + item.serviceRequestID + "</td><td>" + sername + "</td><td>" + desc + "</td><td>" + item.account.userName + "</td><td>" + ConvertJSONDateToJSDateObject(item.createTime) + "</td></tr>").insertAfter($("#List tr:eq(" + i + ")"));
                });
                $("tr.AlternatingRowStyle").dblclick(function () {
                    var ID = $.trim($(this).children().first().html());
                    var rnd = (new Date()).getMilliseconds() + "" + parseInt(Math.random() * 10000);
                    window.open("/ITService/views?servicerequestid=" + ID + "&nocache=" + rnd, "_self");
                });

                document.getElementById('itemCount').value = data.Data.count;
//                if (stype == 1) {
                    var pager = new PagerView('pager');
                    pager.index = parseInt($("input#index").val(), 10);
                    pager.itemCount = data.Data.count;
                    pager.size = parseInt($("input#size").val(), 10);
                    pager.onclick = function (index) {
                        $("input#index").val(index);
                        getToDoWorkList(2);
                    };
                    pager.render();
//                }
            }
        });
    }

